﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace PDNBulkUpdaterCmd
{
	class Program
	{
		static void PrintHeader()
		{
			AssemblyFileVersionAttribute[] version = (AssemblyFileVersionAttribute[])Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);

			Console.WriteLine("Paint .NET Bulk Image Processor");
			Console.WriteLine("Version " + version[0].Version.ToString());
			Console.WriteLine("Copyright © 2010 Keith Newton. All rights reserved.");
			Console.WriteLine("");

			System.Diagnostics.Debug.WriteLine("Paint .NET Bulk Image Processor");
			System.Diagnostics.Debug.WriteLine("Version " + version[0].Version.ToString());
			System.Diagnostics.Debug.WriteLine("Copyright © 2010 Keith Newton. All rights reserved.");
			System.Diagnostics.Debug.WriteLine("");
		}

		static int Main(string[] args)
		{
			PrintHeader();

			string dllPath = System.IO.Path.GetFullPath(System.IO.File.Exists("PDNBulkUpdater.dll") ? "PDNBulkUpdater.dll" : "Effects\\PDNBulkUpdater.dll");
			Assembly asm = null;

			try
			{
				asm = Assembly.LoadFile(dllPath);
			}
			catch(Exception ex)
			{
				Console.WriteLine("Fatal Error: Could not locate PDNBulkUpdater.dll!");
				Console.WriteLine(ex.ToString());

				return 1;
			}

			try
			{
				Type type = asm.GetType("PDNBulkUpdater.CommandLine", true);
				MethodInfo info = type.GetMethod("Run", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod);

				return (int)info.Invoke(null, new object[] { args });
			}
			catch(Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}

			return 1;
		}
	}
}
